/**
 * Created by seeker910 on 2017/6/19.
 * 向导步骤 表单页
 */
Rsd.define('Rsd.zen.dialog.FormGuider', {
    extend: 'Rsd.container.Guider',
    requires: ['Rsd.widget.ModelForm'],
    xtype: 'form-guider',
    width: '100%',
    layout:'fit',
    items:[
        {
            xtype:'model-form'
        }
    ],
    /**
      * @description 表单字段
      */ 
    //formFields:[],
    /*
     *
     * */
    constructor: function FormGuider(config) {
        config = config || {};
        this.apply(config); 
    },
     
    /**
     * 
     */
    loadFormFields:function loadFormFields()
    {
        var mv = this.items[0];
        try {
            mv.fields = this.formFields;
            if(mv instanceof Rsd.widget.ModelForm)
            {
                mv.loadFields();
            } 
        } catch (ex) {
            Rsd.error('FormGuider加载表单失败', 'Rsd.zen.dialog.FormGuider', ex);
        }

        //console.log(mv.height);
        if (mv.height !== 'auto') {
            this.height = 100 + mv.height;
        }
    },
    /**
     *  
     * @param {*} callback 
     * @returns 
     */
     load:function load(callback)
     {
        var me = this;
        me.items[0].loadData(me.data);
        if(me.onLoad || me.onload)
        {
            me.funApplyByIOC(me.onLoad || me.onload,[me,callback]);
        }
        else
       {
            callback(me);
       }

        return this;
     },
    /*
    *
    * */
    getData:function getData() {
         
        if (this.items[0].checkRecord() == false) {
            
            this.items[0].showError();
            return null;
        }

        return this.items[0].getRecord();
    }

},function (type) {

     var _fieldsGetter = function () {
        if(this.__formFields == undefined)
        {
            this.__formFields = [];
        }
        return this.__formFields;
    };

    var _fieldsSetter = function (value) {
        this.__formFields = value;

        this.loadFormFields();
    }

    this.defineProperty(type,"formFields", _fieldsGetter, _fieldsSetter,true);

    this.defineProperty(type,'form', function(){return this.items[0];}, function(value){ this.items[0] = value; }, false);
    
});